/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.bff.slimserver.utils;

import com.bff.bjj.musicobjects.BJJAlbum;
import com.bff.bjj.musicobjects.BJJArtist;
import com.bff.bjj.musicobjects.BJJGenre;
import com.bff.bjj.musicobjects.BJJPlayableItem;
import com.bff.bjj.musicobjects.BJJSong;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import org.bff.slimserver.musicobjects.SlimAlbum;
import org.bff.slimserver.musicobjects.SlimArtist;
import org.bff.slimserver.musicobjects.SlimGenre;
import org.bff.slimserver.musicobjects.SlimPlayableItem;
import org.bff.slimserver.musicobjects.SlimSong;

/**
 *
 * @author Bill
 */
public class ConvertUtils {

    public static SlimArtist convertArtist(BJJArtist artist) {
        SlimArtist slimArtist = null;
        if (artist != null) {
            slimArtist = new SlimArtist(artist.getId(), artist.getName());
            slimArtist.setAlbum(convertAlbum(artist.getAlbum()));
            slimArtist.setBitrate(artist.getBitrate());
            slimArtist.setComment(artist.getComment());
        }
        return slimArtist;
    }

    public static SlimAlbum convertAlbum(BJJAlbum album) {
        SlimAlbum slimAlbum = null;
        if (album != null) {
            slimAlbum = new SlimAlbum(album.getId(), album.getName());
            slimAlbum.setArtist(album.getArtist());
            slimAlbum.setArtworkTrackId(album.getArtworkTrackId());
            convertItem(slimAlbum, album);
        }
        return slimAlbum;
    }

    public static SlimGenre convertGenre(BJJGenre genre) {
        SlimGenre slimGenre = null;
        if (genre != null) {
            slimGenre = new SlimGenre(genre.getId(), genre.getName());
        }
        return slimGenre;
    }

    /**
     * Converts the non bjjItem to the slimItem
     * @param slimItem
     * @param bjjItem 
     */
    private static void convertItem(SlimPlayableItem slimItem, BJJPlayableItem bjjItem) {
        slimItem.setBitrate(bjjItem.getBitrate());
        slimItem.setComment(bjjItem.getComment());
        slimItem.setId(bjjItem.getId());
        slimItem.setImageUrl(bjjItem.getImageUrl());
        slimItem.setLength(bjjItem.getLength());
        slimItem.setName(bjjItem.getName());
        slimItem.setRating(bjjItem.getRating());
        slimItem.setRemote(bjjItem.isRemote());
        slimItem.setTrack(bjjItem.getTrack());
        slimItem.setType(bjjItem.getType());
        slimItem.setUrl(bjjItem.getUrl());
        slimItem.setYear(bjjItem.getYear());
    }

    private static void convertSlimItem(BJJPlayableItem bjjItem, SlimPlayableItem slimItem) {
        bjjItem.setBitrate(slimItem.getBitrate());
        bjjItem.setComment(slimItem.getComment());
        bjjItem.setId(slimItem.getId());
        bjjItem.setImageUrl(slimItem.getImageUrl());
        bjjItem.setLength(slimItem.getLength());
        bjjItem.setName(slimItem.getName());
        bjjItem.setRating(slimItem.getRating());
        bjjItem.setRemote(slimItem.isRemote());
        bjjItem.setTrack(slimItem.getTrack());
        bjjItem.setType(slimItem.getType());
        bjjItem.setUrl(slimItem.getUrl());
        bjjItem.setYear(slimItem.getYear());
    }

    public static Collection<BJJSong> convertSongs(Collection<SlimSong> songs) {
        List<BJJSong> bjjSongs = new ArrayList<BJJSong>();

        for (SlimSong s : songs) {
            BJJSong bjjSong = new BJJSong();
            convertSlimItem(bjjSong, s);
            bjjSongs.add(bjjSong);
        }
        return bjjSongs;
    }

    public static BJJSong convertSong(SlimSong lookupSong) {
        BJJSong bjjSong = new BJJSong();
        convertItem(lookupSong, bjjSong);
        return bjjSong;
    }
}
